package com.ctech.wsgen.dao;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.ctech.wsgen.model.ItemCategory;
import com.ctech.wsgen.model.Manufacture;
import com.ctech.wsgen.model.Site;

public class SiteDaoJdbc implements SiteDao {

	private JdbcTemplate jdbcTemplate;

	public SiteDaoJdbc() { }
	
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	@SuppressWarnings("unchecked")
	public List<ItemCategory> queryItemCategories(Site site) {
		return (List<ItemCategory>) jdbcTemplate.query(
				site.getSql_queryItemCategories(), 
				new ItemCategoryRowMapper()
				);
	}

	@SuppressWarnings("unchecked")
	public List<Manufacture> queryManufactures(Site site) {
		return (List<Manufacture>) jdbcTemplate.query(
				site.getSql_queryManufactures(), 
				new ManufactureRowMapper()
				);
	}

}
